<?php

namespace App\Admin\Controllers\Shipping;

use App\Admin\Repositories\Shipping\CmcOrderShippingFee;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CmcOrderShippingFeeController extends AdminController
{
    /**
     * Make a grid builder
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CmcOrderShippingFee(), function (Grid $grid) {
            $grid->column('shipping_fee_id')->sortable();
            $grid->column('shipping_fee_name')->sortable();
            $grid->column('is_default', '是否为默认模板')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '默认',
                    1 => '不是默认',
                ])
            );

            $grid->column('weight_is_use', '是否启用重量运费')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '使用',
                    1 => '不使用',
                ])
            );
            $grid->column('weight_snum');
            $grid->column('weight_sprice');
            $grid->column('weight_xnum');
            $grid->column('weight_xprice');

            $grid->column('volume_is_use', '是否启用重量运费')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '使用',
                    1 => '不使用',
                ])
            );
            $grid->column('volume_snum');
            $grid->column('volume_sprice');
            $grid->column('volume_xnum');
            $grid->column('volume_xprice');
            $grid->column('bynum_is_use', '')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '使用',
                    1 => '不使用',
                ])
            );
            $grid->column('bynum_snum');
            $grid->column('bynum_sprice');
            $grid->column('bynum_xnum');
            $grid->column('bynum_xprice');
            $grid->column('bynum_is_use', '')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '使用',
                    1 => '不使用',
                ])
            );
            $grid->column('create_time');
            $grid->column('update_time');

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcOrderShippingFee(), function (Show $show) {
            $show->field('shipping_fee_id');
            $show->field('is_default');
            $show->field('co_id');
            $show->field('shop_id');
            $show->field('province_id_array');
            $show->field('city_id_array');
            $show->field('weight_is_use');
            $show->field('weight_snum');
            $show->field('weight_sprice');
            $show->field('weight_xnum');
            $show->field('weight_xprice');
            $show->field('volume_is_use');
            $show->field('volume_snum');
            $show->field('volume_sprice');
            $show->field('volume_xnum');
            $show->field('volume_xprice');
            $show->field('bynum_is_use');
            $show->field('bynum_snum');
            $show->field('bynum_sprice');
            $show->field('bynum_xnum');
            $show->field('bynum_xprice');
            $show->field('create_time');
            $show->field('update_time');
            $show->field('district_id_array');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcOrderShippingFee(), function (Form $form) {
            $form->display('shipping_fee_id');

            $form->text('weight_snum');
            $form->text('weight_sprice');
            $form->text('weight_xnum');
            $form->text('weight_xprice');
            $form->text('volume_is_use');
            $form->text('volume_snum');
            $form->text('volume_sprice');
            $form->text('volume_xnum');
            $form->text('volume_xprice');
            $form->text('bynum_is_use');
            $form->text('bynum_snum');
            $form->text('bynum_sprice');
            $form->text('bynum_xnum');
            $form->text('bynum_xprice');
            $form->datetime('create_time');
            $form->datetime('update_time');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
